%
%
% test_view.m
% this test file is based on couch4mat tutorial.
% edited by H. Kim on Dec. 2011
% added usage examples of couch view creation/query.
%
%
%

c=couch
% you have to have the following line with your id/password
c.url='http://id:password@localhost:5984';

% create db
c=couch(c,'create db','mydb')

% get all databases
c=couch(c,'all_dbs')

% insert a row
d=couch(c,'insert doc','{"hello":"world"}');
% insert another row
lala.hello='world';lala.randM=rand(5);d=couch(c,'insert doc',lala)

% get all docs
c=couch(c,'all_docs')
c.db.all_docs

% modified by H. Kim on Dec. 2011
% row{end} in tutorial --> row(end)
id = c.db.all_docs.rows(end).id
%[c,doc]=couch(c,'get doc',id)
doc=couch(c,'get doc',id)

%json=urlread([c.url,'/',c.db.name,'/',id])
%doc=json2mat(json)
%randM=doc.randM

%[c,doc]=couch(c,'delete doc',id);
%c.db.all_docs

% create view
c.design_name='simpleview';
simpleview_json=['{' ...
   '"_id" : "_design/example",' ...
   '"views": {'...
         '"show_by_hello": {' ...
            '"map" : "function(doc) { emit(doc.hello, doc) }"' ...
         '}' ...
   '}'...
'}'];

c=couch(c,'create view',simpleview_json)
c.curl
c.curl.msg
c.curl.call
c.curl.json

% get view
[c,doc]=couch(c,'get view','show_by_hello');
doc

% delete db
d=couch(c,'delete db')






